package com.bolt.report.business.modules.report.dto.converter;

import com.bolt.report.business.modules.dataset.dto.converter.ReportDataSetConverter;
import com.bolt.report.business.modules.report.dto.ReportDTO;
import com.bolt.report.business.modules.report.entity.ReportEntity;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class ReportConverter {
    private ReportConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param report DO对象
     * @return DTO对象
     */
    public static ReportDTO toDTO(ReportEntity report) {
        if (Objects.isNull(report)) {
            return null;
        }
        ReportDTO result = new ReportDTO();
        result.setId(report.getId());
        result.setCode(report.getCode());
        result.setName(report.getName());
        result.setNote(report.getNote());
        result.setStatus(report.getStatus());
        result.setType(report.getType());
        result.setContextDef(report.getContextDef());
        result.setDelFlag(report.getDelFlag());
        result.setTemplate(report.getTemplate());
        result.setViewCount(report.getViewCount());
        result.setCssStr(report.getCssStr());
        result.setJsStr(report.getJsStr());
        result.setDataSets(ReportDataSetConverter.toDTO(report.getDataSets()));

        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param report DO对象
     * @return VO对象
     */
    public static ReportEntity toEntity(ReportDTO report) {
        if (Objects.isNull(report)) {
            return null;
        }
        ReportEntity result = new ReportEntity();
        result.setId(report.getId());
        result.setCode(report.getCode());
        result.setName(report.getName());
        result.setNote(report.getNote());
        result.setStatus(report.getStatus());
        result.setType(report.getType());
        result.setContextDef(report.getContextDef());
        result.setDelFlag(report.getDelFlag());
        result.setTemplate(report.getTemplate());
        result.setViewCount(report.getViewCount());
        result.setCssStr(report.getCssStr());
        result.setJsStr(report.getJsStr());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param report DO对象
     * @return VO对象
     */
    public static ReportEntity toEntity(ReportEntity result, ReportDTO report) {
        if (Objects.isNull(report)) {
            return null;
        }
        result.setCode(report.getCode());
        result.setName(report.getName());
        result.setNote(report.getNote());
        result.setType(report.getType());
        result.setContextDef(report.getContextDef());
        result.setTemplate(report.getTemplate());
        result.setCssStr(report.getCssStr());
        result.setJsStr(report.getJsStr());
// TODO
        return result;
    }

    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param reportList Entity集合对象
     * @return DTO对象
     */
    public static List<ReportDTO> toDTO(List<ReportEntity> reportList) {
        if (Objects.isNull(reportList)) {
            return null;
        }
        return reportList.stream().map(ReportConverter::toDTO).collect(Collectors.toList());
    }

}
